from django.db import models

class Author(models.Model):
    name = models.CharField(max_length=100)
    age = models.IntegerField()
    email = models.EmailField(max_length=100)
    phone = models.CharField(max_length=20)
    ssn = models.CharField(max_length=11)
    credit_card = models.CharField(max_length=16)
    api_key = models.CharField(max_length=64)
    friends = models.ManyToManyField("self", blank=True)

# 核心：Book模型的contact字段必须正确关联Author，且无多余干扰字段
class Book(models.Model):
    isbn = models.CharField(max_length=13)  # 修正ISBN长度为标准13位（非必须，仅规范）
    name = models.CharField(max_length=255)
    pages = models.IntegerField()
    rating = models.FloatField()
    price = models.DecimalField(decimal_places=2, max_digits=6)
    # 多对多字段（不影响漏洞，保留）
    authors = models.ManyToManyField(Author, related_name="books")
    # 核心外键：关联Author，用于漏洞利用（必须保留，且无related_name冲突）
    contact = models.ForeignKey(Author, on_delete=models.CASCADE)
    pubdate = models.DateField()
    secret_code = models.CharField(max_length=50)
    drm_key = models.CharField(max_length=128)

# 其他模型不影响漏洞，可保留或删除（此处保留以保持完整性）
class Publisher(models.Model):
    name = models.CharField(max_length=255)
    num_awards = models.IntegerField()
    address = models.TextField()
    tax_id = models.CharField(max_length=20)
    bank_account = models.CharField(max_length=30)

class Store(models.Model):
    name = models.CharField(max_length=255)
    books = models.ManyToManyField(Book)
    original_opening = models.DateTimeField()
    friday_night_closing = models.TimeField()
    area = models.IntegerField(null=True, db_column="surface")